
//
//  NewPostsViewController.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/1/29.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit
import TZImagePickerController
import IQKeyboardManagerSwift
class NewPostsViewController: UIViewController, UITextFieldDelegate, AddCornerUIRectCorner {
    @IBOutlet weak var coverView: UIView!
    @IBOutlet weak var coverButton: UIButton!
    @IBOutlet weak var circleButton: UIButton!
    @IBOutlet weak var contentImageButton: UIButton!
    @IBOutlet weak var titleTextField: UITextField!
    @IBOutlet weak var textCountLabel: UILabel!
    @IBOutlet weak var mainTextView: IQTextView!
    override func viewDidLoad() {
        super.viewDidLoad()
        setNavigationColor(colorState: .black)
        setNavigationBar()
        setUI()
        // Do any additional setup after loading the view.
    }
    
    func setUI() {
        circleButton.layer.cornerRadius = CORNERRADIUS
        contentImageButton.layer.cornerRadius = CORNERRADIUS
        titleTextField.delegate = self
        mainTextView.placeholder = "   请输入内容"
       
        self.addCornerWithView(aView: self.coverView, aCorners: [.topRight, .topLeft], aSize: CGSize(width: CORNERRADIUS, height: CORNERRADIUS))
    }

    func setNavigationBar() {
        let titleButton = UIButton()
        titleButton.setTitle("发布", for: .normal)
        titleButton.setImage(UIImage(named: "icon_address"), for: .normal)
        titleButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0)
        self.navigationItem.titleView = titleButton
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "btn_determine"), style: .done, target: self, action: #selector(doneTap))
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "all_return"), style: .done, target: self, action: #selector(returnRootVC))
    }
    
    @objc func returnRootVC() {
        let showView = CustomShowAlertView()
        showView.show(title: "是否保存为草稿") { (isCancel) in
            if isCancel {
                CustomShowAlertView().show(title: "保存成功", tapClosure: {
                    self.navigationController?.dismiss(animated: true, completion: nil)
                })
            }
        }
    }
    
    @objc func doneTap() {
      let showView = CustomShowAlertView()
        showView.show(title: "发布成功") {
            self.navigationController?.dismiss(animated: true, completion: nil)
        }
    }

    @IBAction func selectContentImageTap(_ sender: UIButton) {
        
    }
    
    @IBAction func selectCircleTap(_ sender: UIButton) {
        let selectTheCircleVC = SelectTheCircleViewController(nibName: "\(SelectTheCircleViewController.self)", bundle: nil)
        navigationController?.pushViewController(selectTheCircleVC, animated: true)
    }
}
